/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.zumbits.avd.comunication;

import br.com.zumbits.avd.comunication.protocol.Copy;
import br.com.zumbits.avd.comunication.protocol.Delete;
import br.com.zumbits.avd.comunication.protocol.Download;
import br.com.zumbits.avd.comunication.protocol.Login;
import br.com.zumbits.avd.comunication.protocol.Logoff;
import br.com.zumbits.avd.comunication.protocol.CreateFolder;
import br.com.zumbits.avd.comunication.protocol.List;
import br.com.zumbits.avd.comunication.protocol.Move;
import br.com.zumbits.avd.comunication.protocol.Upload;
import br.com.zumbits.avd.comunication.protocol.Version;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;

/**
 *
 * @author zumbits
 */
public class Protocol implements Comunication {

    private XStream xstream;

    public Protocol() {
        this.xstream = new XStream(new DomDriver());
    }

    public Login login(String xml) {
        xstream.alias(LOGIN, Login.class);
        return (Login) xstream.fromXML(xml);
    }

    public Logoff logoff(String xml) {
        xstream.alias(LOGOFF, Logoff.class);
        return (Logoff) xstream.fromXML(xml);
    }

    public Download download(String xml) {
        xstream.alias(DOWNLOAD, Download.class);
        return (Download) xstream.fromXML(xml);
    }

    public Upload upload(String xml) {
        xstream.alias(UPLOAD, Upload.class);
        return (Upload) xstream.fromXML(xml);
    }

    public List list(String xml) {
        xstream.alias(LIST, List.class);
        return (List) xstream.fromXML(xml);
    }

    public Move move(String xml) {
        xstream.alias(MOVE, Move.class);
        return (Move) xstream.fromXML(xml);
    }

    public Delete delete(String xml) {
        xstream.alias(DELETE, Delete.class);
        return (Delete) xstream.fromXML(xml);
    }

    public CreateFolder createFolder(String xml) {
        xstream.alias(CREATE_FOLDER, CreateFolder.class);
        return (CreateFolder) xstream.fromXML(xml);
    }

    public Copy copy(String xml) {
        xstream.alias(COPY, Copy.class);
        return (Copy) xstream.fromXML(xml);
    }

    public Version version(String xml) {
        xstream.alias(VERSION, Version.class);
        return (Version) xstream.fromXML(xml);
    }
}
